package models

type SystemMenu struct {
	Id          int       `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
	Parentid	int		  `json:"parentid" xorm:"not null default '' comment('父Id') INT(11)"`
	Level       int       `json:"level" xorm:"not null default 0 comment('层级') TINYINT(4)"`
	Name        string    `json:"name" xorm:"not null default '' comment('名称') VARCHAR(100)"`
	Title       string    `json:"title" xorm:"not null default '' comment('菜单显示名称') VARCHAR(100)"`
}
var systemmenu = "system_menu"


func  (s *SystemMenu) GetByUserId(uid int) ([]SystemMenu,error) {

	var menu []SystemMenu
	err := mEngine.Table(systemmenu).Distinct(systemmenu+".*").
		Join("INNER", systemrolemenu, systemrolemenu+".menu_id= "+systemmenu+".id").
		Join("INNER", systemuserrole, systemrolemenu+".role_id= "+systemuserrole+".role_id").
		Where(systemuserrole+".user_id = ?", uid).
		Find(&menu)


	return menu,err


}
